using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Module.Common.Models;
using Module.Core.EntitiesInfo;

namespace Module.Core.DAO
{
	public class CMSUserRoleZoneDAO
	{
		#region Fields

		protected string connectionStringName;

		#endregion
		
		#region Methods

		/// <summary>
		/// Selects all records from the CMS_UserRoleZone table.
		/// </summary>
        public virtual int Insert(CMSUserRoleZoneInfo cmsUserRoleZoneInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@RoleID", cmsUserRoleZoneInfo.RoleID),
				new SqlParameter("@ZoneIDLang", cmsUserRoleZoneInfo.ZoneIDLang),
				new SqlParameter("@CheckRole", cmsUserRoleZoneInfo.CheckRole),
				new SqlParameter("@Lang", cmsUserRoleZoneInfo.Lang)
			};

            return (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "CMS_UserRoleZone_Insert", parameters);
        }
        public CHRTList<CMSUserRoleZoneInfo> CheckUserRoleZone(int roleID, int zoneIDLang,int lang)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@RoleID", roleID),
                new SqlParameter("@ZoneIDLang", zoneIDLang),
                new SqlParameter("@Lang", lang)
			};
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "CMS_UserRoleZone_CheckUserID",parameters))
            {
                CHRTList<CMSUserRoleZoneInfo> cMSUserRoleZoneInfoList = new CHRTList<CMSUserRoleZoneInfo>();
                while (dataReader.Read())
                {
                    CMSUserRoleZoneInfo cMSUserRoleZoneInfo = MakeCMSUserRoleZoneInfo(dataReader);
                    cMSUserRoleZoneInfoList.Add(cMSUserRoleZoneInfo);
                }

                return cMSUserRoleZoneInfoList;
            }
        }
        public virtual void Delete(CMSUserRoleZoneInfo cmsUserRoleZoneInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@RoleID", cmsUserRoleZoneInfo.RoleID),
                new SqlParameter("@ZoneIDLang", cmsUserRoleZoneInfo.ZoneIDLang),
                new SqlParameter("@Lang", cmsUserRoleZoneInfo.Lang)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "CMS_UserRoleZone_Delete", parameters);
        }
		public CHRTList<CMSUserRoleZoneInfo> SelectAll()
		{
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "CMS_UserRoleZone_SelectAll"))
			{
				CHRTList<CMSUserRoleZoneInfo> cMSUserRoleZoneInfoList = new CHRTList<CMSUserRoleZoneInfo>();
				while (dataReader.Read())
				{
					CMSUserRoleZoneInfo cMSUserRoleZoneInfo = MakeCMSUserRoleZoneInfo(dataReader);
					cMSUserRoleZoneInfoList.Add(cMSUserRoleZoneInfo);
				}

				return cMSUserRoleZoneInfoList;
			}
		}

		/// <summary>
		/// Creates a new instance of the CMS_UserRoleZone class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected virtual CMSUserRoleZoneInfo MakeCMSUserRoleZoneInfo(SqlDataReader dataReader)
		{
			CMSUserRoleZoneInfo cMSUserRoleZoneInfo = new CMSUserRoleZoneInfo();
			cMSUserRoleZoneInfo.UserRoleZoneID = SqlClientUtility.GetInt32(dataReader,DbConstants.CMS_USERROLEZONE.USERROLEZONEID, 0);
			cMSUserRoleZoneInfo.Lang = SqlClientUtility.GetInt32(dataReader,DbConstants.CMS_USERROLEZONE.LANG, 0);
			cMSUserRoleZoneInfo.RoleID = SqlClientUtility.GetInt32(dataReader,DbConstants.CMS_USERROLEZONE.ROLEID, 0);
			cMSUserRoleZoneInfo.CheckRole = SqlClientUtility.GetInt32(dataReader,DbConstants.CMS_USERROLEZONE.CHECKROLE, 0);
			cMSUserRoleZoneInfo.ZoneIDLang = SqlClientUtility.GetInt32(dataReader,DbConstants.CMS_USERROLEZONE.ZONEIDLANG, 0);

			return cMSUserRoleZoneInfo;
		}

		#endregion
	}
}
